/*1、编写一个程序，实现堆积排序。
需要输出排序过程中产生的每个堆。*/

#include<stdio.h>
#define MAXN 1024

void adjust(int* head,int i,int n){
    int self = head[i];
    int cur = 2*i+1;
    while( cur < n ){
        if( cur < n-1 && head[cur] < head[cur+1] )++cur; //cur is the larger of two children
        if( head[cur] <= self ){ head[(cur-1)/2]=self;return;} //OK
        head[(cur-1)/2] = head[cur]; cur = 2*cur+1;
    }
    head[(cur-1)/2]=self;return;
}

void print_array(const int* a,int n){for(int i = 0;i<n;i++)printf("%d ",a[i]);putchar('\n');}

void heap_sort_verbose(int* a,int n){
    int i,j,k;
    printf("Make initial heap:\n");
    for(i=(n-1)/2;i>=0;--i){adjust(a,i,n);printf("[adjust #%d]",i);print_array(a,n);}
    printf("Make moves:\n");
    for(i=n-1;i>0;--i){
        j = a[0]; a[0] = a[i]; a[i] = j;
        printf("[Move %d]",j);adjust(a,0,i);print_array(a,n);
    }
}

int main(){
    int n,i;
    int A[MAXN];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",A+i);
    heap_sort_verbose(A,n);
    return 0;
}